<h2>Examples of using events</h2>

<h3>Basic Usage:</h3>
<h4>Case</h4>
This is a simple case: there is a class called "Listen_To_Me" that should trigger events that are of use to a variety of other classes.
For this exmaple, we are interested in when we are about to delete() and save() instances.

<h4>Solution</h4>
First, we will create a listener to handle any events that are triggered by the Listen_To_Me class:
<code>
# handles events triggered by Listen_To_Me, see listen/to/me.class.php
class Listen_To_Me_Handler extends Event_Handler {
	# handles "delete" events
	protected function onDelete(Event_Event $oEvent){
		# supposing there is a Listen_To_Me->getId() method
		echo 'About to delete '.$oEvent->getSource()->getId(); 
	}
	# handles "save" events
	protected function onSave(Event_Event $oEvent){
		# supposing there is a Listen_To_Me->getId() method
		echo 'About to save '.$oEvent->getSource()->getId(); 
	}
}
</code>
Should the Listen_To_Me class trigger any other events: these will be noticed by Listen_To_Me_Handler, but ignored.

Next, the Listen_To_Me class will trigger the required events:
<code>
class Listen_To_Me extends Whatever_You_Like {
	#...
	public function delete(){
		new Event_Event('delete');
		# ...
	}
	public function save(){
		new Event_Event('save');
		# ...
	}
	#...
}
</code>

Finally, we should have the Listen_To_Me_Handler listen to Listen_To_Me classes. This is done by simply providing the classname during
construction (as a string):
<code>
new Listen_To_Me_Handler('Listen_To_Me');
</code>

<h4>Case</h4>
Besides the Listen_To_Me classes, the same handlers should apply to Listen_To_Me_Too. This is a class that does not extend Listen_To_Me.

<h4>Solution</h4>
Just add the name of Listen_To_Me_Too to the list of listeners. Don't forget to trigger the proper events in Listen_To_Me_Too!
<code>
new Listen_To_Me_Handler('Listen_To_Me', 'Listen_To_Me_Too');
</code>

<h4>Case</h4>
There is a whole class of classes that share no inheritance relation, but should trigger the same functionallity when deleted. This
functionallity can not be accessed because of the lack of inheritance relation.

<h4>Solution</h4>
Create an interface, e.g. "Observable".
<code>
interface Observable {}
</code>

Implement this interface in each of the classes you wish to observe
<code>
class This_Is_But_One implements Observable {
	# ...
}
</code>
and have them all trigger a new Event_Event when needed.

Create an Event_Handler as described above, e.g. "Observer" (extends Event_Handler), and set it up to listen to the interface:
<code>
new Observer('Observable');
</code>
</refentry>